<?php

class Account
{
	var $MALE = 'm';
	var $FEMALE = 'f';
	
	var $_customerFirstName;
	var $_customerGender;
	var $_customerId;
	var $_customerLastName;
	
	function Account()
	{
		global $customer_id;
		
		if ($this->isRegistered())
		{
			$sql = 'select * from '.TABLE_CUSTOMERS.' where customers_id = "'.mysql_real_escape_string($customer_id).'" limit 1';
			$results = tep_db_query($sql);
			
			while ($result = tep_db_fetch_array($results))
			{
				$this->_customerId = $customer_id;
				$this->_customerGender = $result['customers_gender'];
				$this->_customerFirstName = $result['customers_firstname'];
				$this->_customerLastName = $result['customers_lastname'];
			}
		}
	}
	
	function getCustomerFirstName()
	{
		return $this->_customerFirstName;
	}
	
	function getCustomerGender()
	{
		return $this->_customerGender;
	}
	
	function getCustomerLastName()
	{
		return $this->_customerLastName;
	}
	
	function getCustomerName()
	{
		return $this->_customerFirstName.' '.$this->_customerLastName;
	}
	
	function isRegistered()
	{
		global $session;
		return $session->isRegistered('customer_id');
	}
	
	function setPassword($password)
	{
		
	}
	
	/**
	 * Get the order history associated with the account
	 * 
	 */
	
	function getOrderHistory($page = 0, $show = MAX_DISPLAY_ORDER_HISTORY)
	{
		// TODO: There must be a batter way to access $languages_id
		global $languages_id;
		
		$history_query_raw = 'select o.orders_id, o.date_purchased, o.delivery_name, o.billing_name, ot.text as order_total, s.orders_status_name from '.TABLE_ORDERS.' o, '.TABLE_ORDERS_TOTAL.' ot, '.TABLE_ORDERS_STATUS.' s where o.customers_id = "'.(int) $this->_customerId.'" and o.orders_id = ot.orders_id and ot.class = "ot_total" and o.orders_status = s.orders_status_id and s.language_id = "'.(int) $languages_id.'" order by orders_id DESC';
		$history_split = new splitPageResults($history_query_raw, MAX_DISPLAY_ORDER_HISTORY);
		$history_split->setResultsClass('Order2'); // TODO: Will need to be changed to 'Order' when the 'Order2' object replaces the old order object
		
		/*
		$history_query = tep_db_query($history_split->sql_query);
		$orders = array();
		
		while ($order = tep_db_fetch_array($history_query)) {
			$order = new $order((int) $order['orders_id']);
			$orders[] = $order;
			
			$products_query = tep_db_query("select count(*) as count from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$history['orders_id'] . "'");
			$history['products'] = tep_db_fetch_array($products_query);
			
			if (tep_not_null($history['delivery_name'])) {
				$history['order_type'] = TEXT_ORDER_SHIPPED_TO;
				$history['order_name'] = $history['delivery_name'];
			} else {
				$history['order_type'] = TEXT_ORDER_BILLED_TO;
				$history['order_name'] = $history['billing_name'];
			}
			
			$history['order_total'] = strip_tags($history['order_total']);
			$history_array[] = $history;
		}
		
		// TODO: We need to return the SplitPageResults object, but with the relevant objects loaded and a more usable API.
		
		return $orders;
		*/
	}
}

?>
